<%--供号商登录后,查看sp的页面,每个sp对应的要能看到流水--%>
<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.baas.model.Sp" %>
<%@ page import="com.qipay.core.entity.Pagination" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <jsp:include page="head.jsp"></jsp:include>
    <jsp:include page="spuser_upload.jsp"></jsp:include>
    <jsp:include page="spuser_code_detail.jsp"></jsp:include>

    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/bootstrap-datepicker3.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/datetimepicker.css">
    <title>支付宝列表</title>
    <script type="text/javascript">
        document.getElementsByTagName("html")[0].style.fontSize = screen.availWidth / 200 + "px";
    </script>

</head>
<body class="devpreview hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box border" >
                        <%
                            Map<String, String> params = (Map<String, String>) request.getAttribute("params");
                            String total = (String)request.getAttribute("total");
                         %>
                        <div class="button-group">
                            <a href="${pageContext.request.contextPath}/spUser/add/alipay">
                                <button type="button" class="btn btn-success btn-sm borderNone" >添加账号</button>
                            </a>
                        </div>
                        <div >
                            <form id="searchForm" action="/spUser/spListQuery" >

                                <div class="new-group date form_datetime">
                                    <label for="from">开始日期：</label>
                                    <input type="text" id="from" name="from" readonly
                                           value="<%= params.containsKey("from") ?params.get("from"):""%>" data-date-format="yyyy-mm-dd hh:ii">
                                </div>
                                <div class="new-group date form_datetime">
                                    <label for="to">结束日期：</label>
                                    <input type="text" id="to" name="to" readonly
                                           value="<%= params.containsKey("to") ?params.get("to"):""%>" data-date-format="yyyy-mm-dd hh:ii">
                                </div>
                                <div class="button-group">
                                    <button type=" submit" class="btn btn-primary btn-sm borderNone" id="btnSearch" >查询</button>
                                </div>
                            </form>
                            <div style="clear: both"></div>
                        </div>

                        <!-- /.box-header -->
                        <div class="tableContent">
                            <table class="table table-bped table-hover">
                                <thead>
                                <tr>
                                    <th width="3%">ID</th>
                                    <th width="8%">SP名称</th>
                                    <%--<th width="8%">商户ID</th>--%>
                                    <th width="8%">渠道</th>
                                    <th width="4%">监控状态</th>
                                    <th width="6%">流水量</th>
                                    <th width="4%">状态</th>
                                    <th width="8%">加入时间</th>

                                    <th width="10%">二维码</th>
                                    <th width="15%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<Sp> articles = (List<Sp>) request.getAttribute("spList");
                                    Pagination pagination = (Pagination) request.getAttribute("pagination");
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<Sp> iter = articles.iterator();
                                        Sp user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();

                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td><%=user.getId()%>
                                    </td>
                                    <td><%=user.getName()%>
                                    </td>
                                    <%--<td><%=user.getMchId()%>--%>
                                    </td>
                                    <td>
                                        <%= user.getBank()%>
                                    </td>
                                    <td class="<%= user.getMchId()!=null&&"0000".equals(user.getMchId())?"success":"danger"%>">
                                        <%= ("0000".equals(user.getMchId())?"已登陆":"未登录")%>
                                    </td>
                                    <td>
                                        <%= user.getCardNo()%>
                                    </td>
                                    <td id="trgoods<%= user.getId()%>"
                                        class="<%= user.getState()!=null&&user.getState()==0?"success":"danger"%>"><%= SiteHelper.getChannelStateString(user.getState())%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getDefaultTimeFormat(user.getCreateDate())%>
                                    </td>

                                    <td>
                                        <%if (user.getFailReason() == null) {%>
                                        <span style="color: red">未上传</span>
                                        <%} else {%>
                                        <span style="color: #00e765">已上传</span>&ensp;
                                        <button type="button" name="uploadCodeDetail"
                                                class="btn btn-success btn-xs borderNone"
                                                data-toggle="modal"
                                                pk="<%=user.getId()%>"
                                                data-target="#spuser_code_detail">
                                            详情
                                        </button>
                                        <%}%>
                                    </td>
                                    <td>
                                        <a href="${pageContext.request.contextPath}/order?spId=<%=user.getId()%>">
                                            <button type="button" class="btn btn-primary btn-sm borderNone" >查看流水</button>
                                        </a>
                                        <%-- 供号商只能查看流水--%>
                                        <button type="button" name="uploadQrCode"
                                                class="btn btn-success btn-sm borderNone"
                                                data-toggle="modal"
                                                pk="<%=user.getId()%>"
                                                data-target="#spuser_upload"
                                                >
                                            上传二维码
                                        </button>
                                        <a href="${pageContext.request.contextPath}/spUser/<%= user.getId()%>">
                                            <button type="button" class="btn btn-warning btn-sm borderNone" >修改
                                            </button>
                                        </a>

                                        <a name="lnkDelete" s="<%= user.getState()!=null&&user.getState()==0?"200":"100"%>"
                                           pk="<%= user.getId()%>" href="javascript:;">
                                            <button type="button"
                                                    class="btn <%= user.getState() != null && user.getState() == 0 ? "btn-danger":"btn-success"%> btn-sm borderNone">
                                                <%= user.getState() != null && user.getState() == 0 ? "禁用" : "启用"%>
                                            </button>
                                        </a>
                                    </td>
                                </tr>

                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="5">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <tr>
                                <td colspan="8">总金额 :<%=total%></td>
                            </tr>
                            <br>
                             <%
                                String query = (String)request.getAttribute("query");
                             %>
                            <div class="col-sm-10">
                                <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                                    <page:page totalSum="<%= pagination.getTotal()%>"
                                               url="<%=query%>"
                                               pageNo="<%= pagination.getPage()%>"
                                               pageSize="<%= pagination.getPageSize()%>"></page:page>
                                </div>
                            </div>
                            <div style="clear: both"></div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>


    <!-- /.content-wrapper -->
    <%--<jsp:include page="foot.jsp"></jsp:include>--%>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datepicker.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
        src="<%= request.getAttribute("StaticHost") %>/js/jquery.ajaxfileupload.js"></script>
<script>
    $('button[name=uploadCodeDetail]').click(function () {
        //先清除之前的金额缓存
        $('#moneyContent').html('');
        //根据查出所有金额，放上去
        var spId = $(this).attr('pk');
        $.ajax({
            url: "${pageContext.request.contextPath}/spUser/code/detail?spId=" + spId,
            type: "GET",
            async: true,//true异步 false同步
            context: this,
            timeout: 10000,
            success: function (data) {
                if (data != null && data.code==200) {
                    var list = data.result;
                    if(list.length>0){
                        for (var i=0;i<list.length;i++){
                            var $money = $('#demoDiv').clone();$money.css("display","");
                            var aliLog = list[i];
                            var money = aliLog.amount/100;
                            if(money>0){
                                $money.find("span").eq(0).html(money);
                            }else {
                                $money.find("span").eq(0).html("任意金额码");
                            }
                            $money.find("button").attr('pk',aliLog.id);
                            // alert($money.html());
                            $('#moneyContent').append($money);
                        }
                        onBindClick();
                    }else {
                        alert("未上传任何二维码");
                        window.location.reload();
                    }
                }else {
                    alert("fail:" + data.message);
                }
            },
            error: function (d, s, b) {
                alert("失败:" + b);
            }
        });
    });

    $('button[name=uploadQrCode]').click(function () {
        var spId = $(this).attr('pk');
        $('#spId00').val(spId);
        //清除缓存
        $("#imggu").val('');
        $('#guName').html('');
    });
    $(function () {
        $('#from, #to').datetimepicker({
            autoclose: true,
            todayBtn: true,
            clearBtn: true,
            language: "zh-CN"});

        $("[name='lnkDelete']").click(function () {
            var that = $(this);
            var pk = $(this).attr("pk");
            var state = $(this).attr("s");
            var isSuccess = state == "200";
            if (confirm(isSuccess ? "确定禁用吗？" : "确定启用吗？")) {
                state = isSuccess ? 1 : 200;
                if (pk > 0) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=setsplstate&id=" + pk + "&id2=" + state,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                window.location.reload();
                            }else {
                                alert("fail:" + "操作失败，请重试");
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }
        });
    });
</script>
</body>
</html>

